import { login } from '@/api/user'
import { Message } from 'element-ui'
import router from '@/router'
export default {
  namespaced: true,
  state() {
    return {
      token: ''
    }
  },
  getters: {},
  mutations: {
    setToken(state, token) {
      state.token = token
    }
  },
  actions: {
    async Login({ commit }, obj) {
      try {
        // await Promise.all([login(obj), login(obj)])
        const { data: res } = await login(obj)
        // console.log(res)
        if (res.code === 200) {
          Message({
            message: '登陆成功',
            type: 'success'
          })
          commit('setToken', res.data.token)
          router.push('/')
        } else {
          Message.error(res.message)
        }
      } catch {
        console.log()
      }
    },
    logout({ commit }) {
      commit('setToken', '')
      router.push('/login')
    }
  },
  modules: {}
}
